package com.hontech.bread.ui.dialog

import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import com.hontech.bread.R
import kotlinx.coroutines.CompletableDeferred

class BillAcceptDialog : DraggableWindow(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT,
    R.layout.dialog_bill_accept,
    false
) {


    private val btnSave = view.findViewById<Button>(R.id.id_bill_accept_btn_save)
    private val btnBack = view.findViewById<Button>(R.id.id_bill_accept_btn_back)
    private val tvMsg = view.findViewById<TextView>(R.id.id_bill_accept_tv_msg)

    private var promise: CompletableDeferred<Boolean>? = null

    init {
        btnSave.setOnClickListener { promise?.complete(true) }
        btnBack.setOnClickListener { promise?.complete(false) }
    }

    suspend fun show(msg: String): Boolean {
        tvMsg.text = msg
        showCenter()
        val p = CompletableDeferred<Boolean>()
        promise = p
        val r = p.await()
        dismiss()
        return r
    }
}